package arith;

import java.text.DecimalFormat;

public class Problem {
	private String template;
	private String problem;
	private double solution;
	private Fraction fracSolution = null;
	private Exponent expSolution = null;
	private int[] factoringSolution;
	String stringSolution;
	int id;
	
	public Problem(String t, String p, double r){
		template = t;
		problem = p;
		solution = r;
	}
	
	public Problem(String t){
		template = t;
	}
	
	public String toString(){
		DecimalFormat df = new DecimalFormat("#.###");
		if(id == 0){
			return "Problem: " + problem/* + "\nSolution: " + df.format(solution)*/;
		}
		if(id == 1){
			return "Problem: " + problem.toString()/* + "\nSolution: " + fracSolution*/;
		}
		if(id == 2){
			return "Problem: " + problem.toString()/* + "\nSolution: " + expSolution*/;
		}
		if(id == 3){
			String s="";
			for(int i=0; i<factoringSolution.length; i++){
				if(i == factoringSolution.length-1){
					s+=""+factoringSolution[i];
				}else{
					s+=""+factoringSolution[i]+", ";
				}
			}
			return "Problem: " + problem.toString()/* + "\nSolution: "+s*/;
		}
		if(id == 4){
			return "Problem: " + problem.toString()/* + "\nSolution: " + stringSolution*/;
		}
		return null;
	}
	
	public void setProblem(String prob){
		problem = prob;
	}
	
	public void setSolution(double sol){
		id = 0;
		solution = sol;
	}
	
	public void setSolution(Fraction sol){
		id = 1;
		fracSolution = sol;
	}
	
	public void setSolution(Exponent sol){
		id = 2;
		expSolution = sol;
	}
	
	public void setSolution(int[] factors){
		id = 3;
		factoringSolution = factors;
	}
	
	public void setSolution(String s){
		id = 4;
		stringSolution = s;
	}
	
	public String getProblem(){
		return problem;
	}
	
	public String getTemplate(){
		return template;
	}
	
	public Object getSolution(){
		if(id == 0){
			return solution;
		}
		if(id == 1){
			return fracSolution;
		}
		if(id == 2){
			return expSolution;
		}
		if(id == 3){
			return factoringSolution;
		}
		if(id == 4){
			return stringSolution;
		}
		return null;
	}
}